<?php

namespace App\Http\Controllers\Admin\PayAndConsume;

use App\Http\Requests\Admin\PayAndConsume\StatDataRequest;
use App\Http\Requests\Admin\PayAndConsume\StatSumDataRequest;
use App\Http\Requests\Admin\PayAndConsume\StatServerRequest;
use App\Http\Requests\Admin\PayAndConsume\StatOnlineRequest;
use App\Services\PayAndConsume\StatService;
use App\Http\Controllers\Admin\BaseController;

class StatController extends BaseController
{

    public function __construct(StatService $statService)
    {
        $this->statService = $statService;
    }

    //综合数据统计
    public function data(StatDataRequest $request)
    {
        $reqStartTime = $request->start_time;
        $reqEndTime = $request->end_time;
        $reqDataType = $request->data_type;

        $reqChannelId = $request->channel_id;
        $reqUniqueId = $request->unique_id;

        $stat = $this->statService->getStatByUniqueID($reqUniqueId, $reqStartTime, $reqEndTime);

        return $this->view(null, compact(['stat', 'reqUniqueId', 'reqChannelId', 'reqStartTime', 'reqEndTime', 'reqDataType']));
    }

    //每日新增留存
    public function retention(StatDataRequest $request)
    {
        $reqUniqueId = $request->unique_id;
        $reqChannelId = $request->channel_id;
        $reqStartTime = $request->start_time;
        $reqEndTime = $request->end_time;
        $reqDataType = $request->data_type;

        $retention = $this->statService->getRetentionByUniqueID($reqUniqueId, $reqStartTime, $reqEndTime);

        return $this->view(null, compact(['retention', 'reqUniqueId', 'reqChannelId', 'reqStartTime', 'reqEndTime', 'reqDataType']));
    }

    //生命周期价值
    public function ltv(StatDataRequest $request)
    {
        $reqUniqueId = $request->unique_id;
        $reqChannelId = $request->channel_id;
        $reqStartTime = $request->start_time;
        $reqEndTime = $request->end_time;
        $reqDataType = $request->data_type;

        //获取渠道信息
        $ltv = $this->statService->getLtvByUniqueID($reqUniqueId, $reqStartTime, $reqEndTime);

        return $this->view(null, compact(['ltv', 'reqUniqueId', 'reqChannelId', 'reqStartTime', 'reqEndTime', 'reqDataType']));
    }

    //单服充值情况
    public function server(StatServerRequest $request)
    {
        $reqUniqueId = $request->unique_id;
        $reqChannelId = $request->channel_id;
        $reqStartTime = $request->start_time;
        $reqDataType = $request->data_type;
        $reqPageSize = $request->page_size;

        $serverStat = $this->statService->getMergeServerByUniqueID($request);

        return $this->view(null, compact(['serverStat', 'reqUniqueId', 'reqChannelId', 'reqStartTime', 'reqDataType', 'reqPageSize']));
    }

    //分时在线统计
    public function online(StatOnlineRequest $request)
    {
        $reqUniqueId = $request->unique_id;
        $reqChannelId = $request->channel_id;
        $reqStartTime = $request->start_time;
        $reqEndTime = $request->end_time;
        $reqDataType = $request->data_type;

        $series = '[]';
        $time = '[]';
        $legendData = ['在线人数'];
        $data = [];

        $series = $this->statService->getOnline($request, $time, $legendData, $data);


        return $this->view(null, compact(['reqUniqueId', 'reqChannelId', 'reqStartTime', 'reqEndTime', 'reqDataType', 'time', 'series', 'legendData', 'data']));
    }

    //实时在线情况
    public function liveOnline(StatDataRequest $request)
    {
        $reqUniqueId = $request->unique_id;
        $reqChannelId = $request->channel_id;
        $reqStartTime = $request->start_time;
        $reqEndTime = $request->end_time;
        $reqDataType = $request->data_type;
        //获取渠道信息
        $time = '[]';
        $rushHour = '[]';
        $avg = '[]';

        $data = $this->statService->getLiveOnline($request, $time, $rushHour, $avg);

        return $this->view(null, compact(['reqUniqueId', 'reqChannelId', 'reqStartTime', 'reqEndTime', 'reqDataType', 'time', 'rushHour', 'avg', 'data']));
    }

    //玩家等级分布
    public function userLevel(StatDataRequest $request)
    {
        $reqChannelId = $request->channel_id;
        $reqUniqueId = $request->unique_id;

        $reqStartTime = $request->start_time;
        $reqEndTime = $request->end_time;

        $reqDataType = $request->data_type;

        $levelX = '[]';
        $amountY = '[]';

        $data = $this->statService->getUserLevel($request, $levelX, $amountY, $totalActiveUsers);

        return $this->view(null, compact(['reqUniqueId', 'reqChannelId', 'reqStartTime', 'reqEndTime', 'reqDataType', 'levelX', 'amountY', 'data', 'totalActiveUsers']));
    }

    //汇总数据统计
    public function sumData(StatSumDataRequest $request)
    {
        $reqStartTime = $request->start_time;
        $reqEndTime = $request->end_time;
        $reqDataType = $request->data_type;

        $stat = $this->statService->getChannelStat($request);

        return view('admin.stat.sumData', compact(['stat', 'reqStartTime', 'reqEndTime', 'reqDataType']));
    }
}
